package com.RedRiver.hospitalsystem.record_service.app.controller;


import cn.hutool.core.bean.BeanUtil;
import com.RedRiver.hospitalsystem.record_service.app.utils.TokenGet;
import com.RedRiver.hospitalsystem.record_service.client.SerialClient;
import com.RedRiver.hospitalsystem.record_service.client.param.CreateSerialParam;
import com.RedRiver.hospitalsystem.record_service.client.result.GetTimeByIdResult;
import com.RedRiver.hospitalsystem.record_service.form.CreateSerialForm;
import com.RedRiver.hospitalsystem.record_service.info.GetTimeByIdInfo;
import com.RedRiver.hospitalsystem.record_service.service.SerialService;
import com.RedRiver.hospitalsystem.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/serial")
@Api(tags = "挂号相关")
public class SerialController implements SerialClient {

    @Resource
    private TokenGet tokenGet;

    @Resource
    private SerialService serialService;

    @Override
    @ApiOperation("挂号")
    public Result<?> createSerial(CreateSerialParam serialParam) {
        CreateSerialForm createSerialForm = BeanUtil.copyProperties(serialParam, CreateSerialForm.class);
        return serialService.addSerial(createSerialForm);
    }

    @Override
    @ApiOperation("叫号")
    public Result<?> getnextone() {
        Integer accountId = tokenGet.getAccountId();
        return serialService.getNext(accountId);
    }

    @Override
    @ApiOperation("根据挂号编号查询时间")
    public Result<GetTimeByIdResult> getTimeById(@ApiParam("挂号编号") @RequestParam("id")Integer id) {
        GetTimeByIdInfo timeByIdInfo=serialService.getTime(id);
        GetTimeByIdResult result = BeanUtil.copyProperties(timeByIdInfo, GetTimeByIdResult.class);
        return Result.getInstance(GetTimeByIdResult.class).setData(result);
    }
}

